VENN2

This program will solve survey problems dealing with 1, 2 or 3 sets inside a universal set. The program first asks for the number of sets and is limited to using just 1, 2 or 3 sets. Next it will draw a picture of a Venn Diagram with the sets labeled. These labels correspond to the regions that you may know or are trying to find. Since each person may label regions differently, the diagram serves this purpose for computational aspects. Next the program will ask for the regions known as well as the cardinality. Here it is a little different than some may think. So here is the description of how to enter in this information. Please keep the diagram in mind as you identify the regions. Suppose we have sets A, B and C in a survey problem and we know the cardinality of the set A and the total number surveyed. We would enter in this fact as follows:
1) The regions known are entered in as lists so you'll begin with a beginning brace, {.
2) Then you would enter in 2356 exactly like this so signify that set A's cardinality is known. What this tells the program is that regions 2, 3, 5, and 6 in the diagram collectively sum up to a value. The program will take this entry in the list, convert it to a string, and then place a 1 in the respective columns of a matrix. 
3) If you know the total number surveyed you would enter 12345678 exactly like this so the program will convert each of these individual entries to a 1 in a matrix. 
4) Note that the numbers themselves do not need to be listed in ascending order, any order will do because the program does a character search to replace the matrix entry with a 1 in that respective column. 
5) Enter in each region, single, double, triples, etc as the digits until all known information about the sets is entered and then close the list with an ending brace, }.

Now the program will ask for the cardinality of these known regions. Keep the order in mind because the cardinality of the collective known regions must be maintained. The program will convert this list to a matrix to augment to the matrix generated by the regions entered in before. It will error check to make sure there is enough information for a unique solution at this point. If not it will not continue. See the example below that describes this part of the process in more detail. 

After this information is entered, the program will rref the matrix and essentially solve the problem. It will output the region number and the cardinality of each region considered by using the Text command.

The variables used to run this program are as follows:
S = number of sets
N, O = dimension of L1 and L2 respectively containing information about the sets
L1 = regions whose collective cardinality is known
L2 = cardinality of the regions
Xmin, Xmax, Ymin, Ymax to size up graphing window for viewing diagram
Y1, L3 and L4 are used for converting information about the regions into strings
I, J and K = counters for loops
[A] = matrix used to store information about which regions are known
[B] = matrix used to store cardinality of collective regions
[C] = rref format of augmented [A] and [B] to report the solution
lCHKL = list used to check to see if the problem has a solution
C = counter used to count number of zeros in last row of [C]
L5 and L6 = used to store and display results to the screen using the Text command

Example: Human blood is typed Rh+ or Rh-. This Rh factor is called an antigen. There are two other antigens known as A and B types. Blood lacking both A and B types is called type O. Sketch a Venn Diagram showing the three types of antigens, A, B, and Rh, and label each of the eight regions. For example, O+ is inside the Rh set (anything in Rh is positive), but outside both A and B. On the other hand, O- is that region outside all three circles. In a survey of 100 people, the following information was collected:
54 have type A,
51 have type B,
24 have type AB (type A and type B)
38 have type B- or type AB-,
13 have type AB-,
19 have type O,
30 have type A but not type B or type O,
27 have type A+ or O+, 
0 have type O-.

Determine how many individuals are in each category.

Answer via Program: The program will begin by asking how many sets. The number of sets is 3, one for A-, one for B- and one for O+. Next the program will display the three set Venn Diagram with labels for each of the 8 regions generated. Following this, the program will ask for the regions whose cardinality is known. In our example we have the following regions that are known:
{1, 2356, 3467, 36, 34, 3, 8, 25, 58}
The associated cardinality would be listed as:
{0, 54, 51, 24, 38, 13, 19, 30, 27}
Notice I did not put the total in 12345678 and 100 in the respective lists. The reason being is that the calculator will not perform a rref command if the number of rows supercedes the number of columns in a matrix. Also, this problem already supplies more than enough information. Even this situation provides too much information. You only need eight entries, not nine to determine a unique solution (the rref result will have the last row in Matrix [C] all zeros accounting for this fact).
The program will then produce two columns:
Region			Cardinality
1			0
2			22
3			13
4			25
5			8
6			11
7			2
8			19

This is the answer we seek. 